import yaml

from tools.sqltools import Dbmysql

class parse_yaml():
    def open_yaml(self,file, key_name):
        # 读取yaml，取出关键数据，用parse解析
        with open(file,encoding="utf-8") as f:
            data = yaml.load(f)
            res = self.parse(data[key_name])
            return res


    def parse(self,func):
        # 遍历每一个步骤
        for ele in func:
            if 'select' == ele["action"]:
                db = Dbmysql()
                sql_res = db.query(ele["sql"])
                return sql_res

